package edu.hawaii.duedates;

import java.util.Date;

/**
 * The class BookInfoRecord is a Comparable interface to handle the dates and book titles to be 
 * entered into the array list.  The class performs a comparison for sorting.
 * 
 * @author Daniel Arakaki, John Ancheta, Mari-Lee Flestado
 * @version 1.0, October 25, 2008
 *
 */
public class BookInfoRecord implements Comparable<BookInfoRecord> {

  /** A string for the book's due date. */
  private final Date dateDue;  
  
  /** A string for the book's title. */
  private final String bookTitle;
  
  /** A string for the library. */
  private final String sLibrary;
  
  /**
   * The constructor initializes two string and a date objects for use.
   * 
   * @param dateConverted The book's due date.
   * @param bookInfoTwo The book's title.
   * @param sLibrary The library's code.
   */
  public BookInfoRecord(Date dateConverted, String bookInfoTwo, String sLibrary) {
    this.dateDue = new Date(dateConverted.getTime());
    this.bookTitle = bookInfoTwo;
    this.sLibrary = sLibrary;
  }
  
  /**
   * A getter method to retrieve the book's due date.
   * 
   * @return date The date that the book is due.
   */
  public Date getDueDate() {
    return new Date(this.dateDue.getTime());
  }
  
  /**
   * A getter method to retrieve the book's title.
   * 
   * @return A string that is the book's title.
   */
  public String getBookTitle() {
    return this.bookTitle;
  }
  
  /**
   * A getter method to retrieve the library's code.
   * 
   * @return sLibrary A String that represents the Library code.
   */
  public String getLibrary() {
    return this.sLibrary;
  }
  
  /**
   * Overriding the equals method and checking if the Date values are equal 
   * and String values are equal.
   * 
   * @return true If the date values are equal and string values are equal.
   *         false If the date values are not equal and string values are not equal.
   *         
   * @param obj The String bookTitle or the Date dateDue.
   */
  @Override
  public boolean equals(Object obj) {
    
    if (obj instanceof BookInfoRecord) {
      BookInfoRecord pair = (BookInfoRecord) obj;
      return pair.getDueDate().equals(this.dateDue) && pair.getBookTitle().equals(this.bookTitle);
    }
    return false;
  }
  
  /**
   * Overriding default hashCode. 
   * 
   * @return Returning a unique BookInfoRecord hashCode.
   */
  @Override
  public int hashCode() {
    return this.dateDue.hashCode() + this.bookTitle.hashCode();
  }

  /**
   * The compare method does a comparison of dates so it sorts the dates in ascending order.
   * 
   * @param bookInfo The argument is a parameterized type.
   * 
   * @return results An integer that flags the sort method.
   */
  public int compareTo(BookInfoRecord bookInfo) {
    Date date = bookInfo.getDueDate(); 
    return this.dateDue.compareTo(date);
  }
}
